/********************************************************************************
 *      Copyright:  (C) 2022 SCEUC
 *                  All rights reserved.
 *
 *       Filename:  at91_gpio.h
 *    Description:  This head file is GPIO operator functions 
 *
 *        Version:  1.0.0(2022年06月28日)
 *         Author:  Zhang.Kang <13874854275@163.com>
 *      ChangeLog:  1, Release initial version on "2022年06月28日 13时29分37秒"
 *                 
 ********************************************************************************/

#ifndef  _AT91_GPIO_H_
#define  _AT91_GPIO_H_

#include <stddef.h>
#include <stdbool.h>

#define CFG_GPIO_DIR "/sys/class/gpio"
#define CFG_GPIO_SYS_FILE_EXPORTED_TIME_IN_100MS 10

/*+-------------------------------------------------------------------------
 *| Follow funcitons $gpio functions should be a string, format as: 
 *|      "PA0"~"PA31" "PB0"~"PB31"  "PC0"~"PC31" "PD0"~"PD18" 
 *+-------------------------------------------------------------------------*/

#define HIGHLEVEL         1   
#define LOWLEVEL          0
int at91_gpio_set(char *gpio, int level);


/*return value: <0:failure    >0:highlevel    =0:lowlevel  */
int at91_gpio_get(char *gpio);


/*+---------------------------+
 *|    GPIO lowlevel API      |
 *+---------------------------+*/

int gpio_is_exported(char *gpio);
int gpio_export(char *gpio);
int gpio_unexport(char *gpio);

#define DIR_OUTPUT         1   
#define DIR_INPUT          0
int gpio_set_direction(char *gpio, bool output);


#define EDGE_RISING        1
#define EDGE_RISING_NONE   0
#define EDGE_FALLING       1
#define EDGE_FALLING_NONE  0
int gpio_set_edge(char *gpio, bool rising, bool falling);


#endif   /* ----- #ifndef _AT91_GPIO_H_  ----- */

